package com.pomr.model.simstorage;

import java.io.Serializable;

import javax.persistence.*;

import org.hibernate.annotations.Formula;
import org.hibernate.annotations.GenericGenerator;

import com.pomr.model.equipmentstorage.EquipmentStorage;
import com.pomr.model.menu.EquipmentCondition;
import com.pomr.model.menu.EquipmentStatus;
import com.pomr.model.menu.NetworkOperator;
import com.pomr.model.synthesize.Manufacturer;
import com.pomr.model.sys.Agency;

/**
 * SIM卡库存明细
 * @author Administrator
 *
 */
@Entity
@Table(name="sim_storage_detail",uniqueConstraints = {@UniqueConstraint(columnNames={"storage_id","sn"})})
public class SimStorageDetail implements Serializable{
	
	public double getEarnestmoney() {
		return earnestmoney;
	}

	public void setEarnestmoney(double earnestmoney) {
		this.earnestmoney = earnestmoney;
	}

	public String getIccid() {
		return iccid;
	}

	public void setIccid(String iccid) {
		this.iccid = iccid;
	}

	public String getReason() {
		return reason;
	}

	public void setReason(String reason) {
		this.reason = reason;
	}

	public String getAppid() {
		return appid;
	}

	public void setAppid(String appid) {
		this.appid = appid;
	}

	public String getImsi() {
		return imsi;
	}

	public void setImsi(String imsi) {
		this.imsi = imsi;
	}

	public String getCondition() {
		return condition;
	}

	public void setCondition(String condition) {
		this.condition = condition;
	}

	public EquipmentCondition getEquipmentCon() {
		return equipmentCon;
	}

	public void setEquipmentCon(EquipmentCondition equipmentCon) {
		this.equipmentCon = equipmentCon;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	public EquipmentStatus getEquipmentStatus() {
		return equipmentStatus;
	}

	public void setEquipmentStatus(EquipmentStatus equipmentStatus) {
		this.equipmentStatus = equipmentStatus;
	}


	public SimStorage getSimStorage() {
		return simStorage;
	}

	public void setSimStorage(SimStorage simStorage) {
		this.simStorage = simStorage;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	

	public String getNerworkName() {
		return nerworkName;
	}

	public void setNerworkName(String nerworkName) {
		this.nerworkName = nerworkName;
	}


	public String getAgencyName() {
		return agencyName;
	}

	public void setAgencyName(String agencyName) {
		this.agencyName = agencyName;
	}

	public String getManufacturerName() {
		return manufacturerName;
	}

	public void setManufacturerName(String manufacturerName) {
		this.manufacturerName = manufacturerName;
	}

	public String getsN() {
		return sN;
	}

	public void setsN(String sN) {
		this.sN = sN;
	}

	public SimFlow getFlow() {
		return flow;
	}

	public void setFlow(SimFlow flow) {
		this.flow = flow;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO, generator = "native")
    @GenericGenerator(name = "native", strategy = "native")//AUTO 在mysql中需要指定使用本地策略生成主键值
	private Integer id;//主键
	
	
	@Formula("(select e.name from menu_network e where e.id=(select ss.nerwork_id from sim_storage ss where ss.id=storage_id))")
	private String nerworkName;//网络运营商名称
	
	
	
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="storage_id")
	private SimStorage simStorage;
	
	@Formula("(select a.name from agency a where a.id=(select ss1.agency_id from sim_storage ss1 where ss1.id=storage_id))")
	private String agencyName;//机构名称
	
	@Formula("(select m.name from manufacturer m where m.id=(select ss2.manufacturer_id from sim_storage ss2 where ss2.id=storage_id))")
	private String manufacturerName;//厂商名称
	
	@Column(name="sn")
	private String sN;//SN编码
	
	@Column(name="imsi", length=30)
	private String imsi;//移动用户识别码
	
	@Column(name="iccid", length=30)
	private String iccid;//唯一识别号码
	
	@Column(name="appid", length=20)
	private String appid;//用户名
	
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="status",columnDefinition="int default 1")
	private EquipmentStatus equipmentStatus;//状态 默认值1空闲
	
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="econdition",columnDefinition="int default 1")
	private EquipmentCondition equipmentCon;//状态 默认值1正常
	
	@Formula("(select s.name from menu_equipment_status s where s.id=status)")
	private String status;//厂商名称
	
	@Formula("(select c.name from menu_equipment_condition c where c.id=econdition)")
	private String condition;//厂商名称
	
	@Formula("(select st.earnestmoney from sim_storage st where st.id=storage_id)")
	private double earnestmoney;//定金
	
	@Column(name="remark",length=500)
	private String remark;//备注
	@Column(name="reason",length=500)
	private String reason;//清库原因
	@OneToOne(fetch = FetchType.EAGER,mappedBy = "detail")
	private SimFlow flow;//流量信息

}
